package com.senney.file.io;

import org.junit.Test;

import java.io.File;

/**
 * @author Lanmengye@outlook.com
 * @date 2021/1/2 14:26
 */
public class FileOperationDemo {
    @Test
    public void createFile() throws Exception {
        File file = new File("F:\\test\\a.txt");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        if (file.exists()) file.delete();
        file.createNewFile();
        System.out.println(file.getName());
        System.out.println(file.getAbsolutePath());
    }

    @Test
    public void listFile(){
        File file = new File("D:\\JavaNote");
        listFileRecursive(file);
    }

    private void listFileRecursive(File file) {
        for (File f : file.listFiles()) {
            if (f.isDirectory()) {
                listFileRecursive(f);
            } else {
                System.out.println(f.getAbsolutePath());
            }
        }
    }
}
